const Base = require('./base')
const _ = require('lodash')
class House extends Base {
  get tableName() { return 'House' }
  get virtuals () {
    return {
      priceText () {
        if (this.type == 1) {
          return this.monthPrice ? ('¥' + this.monthPrice + '/月') : '待定'
        } else {
          const priceTextArr = []
          if (this.hourPrice) {
            priceTextArr.push('¥' + this.hourPrice + '/小时') 
          }
          if (this.dayPrice) {
            priceTextArr.push('¥' + this.dayPrice + '/天')
          }
          return priceTextArr.length ? priceTextArr.join(' ') : '待定'
        }
        console.log('type', this.type)
      }
    }
  }
  serialize () {
    const data = super.serialize()
    _.each(['usage', 'facility'], (key) => {
      data[key] = data[key] ? data[key].split(',') : []
    })
    try {
      data.pics = data.pics ? JSON.parse(data.pics) : []
    } catch (e) {
      data.pics = data.pics ? data.pics.split(',') : []
    }
    return data
  }
}

module.exports = House